//
//  OvsCommon.h
//  OvsWork
//
//  Created by 郭壮 on 16/4/15.
//  Copyright © 2016年 Red Persimmon. All rights reserved.
//

#ifndef OvsCommon_h
#define OvsCommon_h

#define kSCREENH [[UIScreen mainScreen] bounds].size.height
#define kSCREENW [[UIScreen mainScreen] bounds].size.width

#define RGBCOLOR(r,g,b) [UIColor colorWithRed:(r)/255.0f green:(g)/255.0f blue:(b)/255.0f alpha:1]

#define RGBACOLOR(r,g,b,a) [UIColor colorWithRed:(r)/255.0 green:(g)/255.0 blue:(b)/255.0 alpha:(a)]

#define WGRandomColor RGBCOLOR(arc4random_uniform(255.0),arc4random_uniform(255.0),arc4random_uniform(255.0))

// 通知中心
#define WGNotificationCenter [NSNotificationCenter defaultCenter]

#define WGStandardUserDefaults [NSUserDefaults standardUserDefaults]

/**
 *  宏
 */
#ifdef DEBUG
//====================================================
// NSLog的一个更好的版本。
// __FILE__返回当前文件的绝对路径，__LINE__返回展开该宏时在文件中的行数，__func__是该宏所在scope的函数名称。
// __VA_ARGS__表示的是宏定义中的...中的所有剩余参数
//====================================================
#define NSLog(format, ...)  do {                                                                            \
fprintf(stderr, "<%s : %d> %s\n",                                           \
[[[NSString stringWithUTF8String:__FILE__] lastPathComponent] UTF8String],  \
__LINE__, __func__);                                                        \
(NSLog)((format), ##__VA_ARGS__);                                           \
fprintf(stderr, "---------- ---------- ----------\n");                      \
} while (0)
#else
#define NSLog(...) {}
#endif

/**
 *  用于解决ios7导航栏挡住视图的问题
 */
#define EDGESLAYOUT(self) if(IOS_7) {\
self.edgesForExtendedLayout = UIRectEdgeNone;\
self.extendedLayoutIncludesOpaqueBars = NO;\
self.modalPresentationCapturesStatusBarAppearance = NO;\
}

//Appdelegate
#define App ((AppDelegate*)([UIApplication sharedApplication].delegate))
//删除缓存
#define remove_sp(a) [[NSUserDefaults standardUserDefaults] removeObjectForKey:a]
//获取缓存
#define get_sp(a) [[NSUserDefaults standardUserDefaults] objectForKey:a]
//添加缓存
#define set_sp(a,b) [[NSUserDefaults standardUserDefaults] setObject:b forKey:a]

//设备类型判断
#define kDeviceIsiPhone4 ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(640, 960), [[UIScreen mainScreen] currentMode].size) : NO)
#define kDeviceIsiPhone5 ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(640, 1136), [[UIScreen mainScreen] currentMode].size) : NO)
#define kDeviceIsiPhone6 ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(750, 1334), [[UIScreen mainScreen] currentMode].size) : NO)
#define kDeviceIsiPhone6Plus ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(1242, 2208), [[UIScreen mainScreen] currentMode].size) : NO)

//IOS6
#define IOS_6  ([[UIDevice currentDevice].systemVersion floatValue]>=6.0)
//IOS7
#define IOS_7  ([[UIDevice currentDevice].systemVersion floatValue]>=7.0)
//IOS8
#define IOS_8  ([[UIDevice currentDevice].systemVersion floatValue]>=8.0)
//IOS9
#define IOS_9  ([[UIDevice currentDevice].systemVersion floatValue]>=9.0)


#define ResizableImageForMode(name,top,left,bottom,right,mode) [IMAGE(name) resizableImageWithCapInsets:UIEdgeInsetsMake(top,left,bottom,right) resizingMode:mode]

#define IMAGE(name) [UIImage imageNamed:name]

/**
 *  用于解决ios7导航栏挡住视图的问题
 */
#define EDGESLAYOUT(self) if(IOS_7) {\
self.edgesForExtendedLayout = UIRectEdgeNone;\
self.extendedLayoutIncludesOpaqueBars = NO;\
self.modalPresentationCapturesStatusBarAppearance = NO;\
}

#endif /* OvsCommon_h */
